﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 整数数组操作
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("请输入数组长度：");
            int x = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("请输入数组元素（一行一个）：");
            double[] arr = new double[x];
            for (int i = 0; i < x; i++)
            {
                arr[i] = Convert.ToDouble(Console.ReadLine());
            }
            Console.WriteLine("\n");
            ArrayOpt arrayOpt = new ArrayOpt();
            arrayOpt.MaxNumber(arr);
            arrayOpt.MinNumber(arr);
            arrayOpt.SumAndAveOfArr(arr);
            Console.ReadLine();
        }

        //class CreateArr
        //{
        //    public void KeyInArr(int[] arr)
        //    {
        //        Console.WriteLine("请输入数组长度：");
        //        int x = Convert.ToInt32(Console.ReadLine());
        //        arr= new int[x];
        //        for (int i = 0; i < x; i++)
        //        {
        //            arr[i] = Convert.ToInt32(Console.ReadLine());
        //        }
        //    }

        //}
        class ArrayOpt
        {
            public void MaxNumber(double[] a)
            {
                double x = a[0];
                for (int i = 0; i < a.Length - 1; i++)
                {
                    if (a[i + 1] > a[i])
                    {
                        x = a[i + 1];
                    }
                }
                Console.Write("数组最大值为：");

                Console.WriteLine(x);
            }
            public void MinNumber(double[] a)
            {
                double n = a[0];
                for (int i = 0; i < a.Length - 1; i++)
                {
                    if (a[i + 1] < a[i])
                    {
                        n = a[i + 1];
                    }
                }
                Console.Write("数组最小值为：");
                Console.WriteLine(n);
            }
            public void SumAndAveOfArr(double[] a)
            {
                double sum = 0;
                for (int i = 0; i < a.Length; i++)
                {
                    sum += a[i];
                }
                Console.Write("数组和为：");
                Console.WriteLine(sum);
                double ave = sum / a.Length;
                Console.Write("数组平均值为：");
                Console.WriteLine(ave);
            }
        }
    }
}
